package echo

import (
	"context"
	"errors"

	"gitee.com/bjf-fhe/apicat/entry"
	nginx_notifier "gitee.com/bjf-fhe/apicat/notify/nginx"
	"gitee.com/bjf-fhe/apicat/platform"
	"gitee.com/bjf-fhe/apicat/source"
	"github.com/spf13/pflag"
)

type Config struct {
	NotifierConfig nginx_notifier.Config
	ens            map[string]*entry.LogEntry
}

func (h *Config) FromMap(m map[string]string) error {
	return h.NotifierConfig.FromMap(m)
}

func (h *Config) AddFlags(set *pflag.FlagSet) {
}

func (h *Config) GetNotifier(ctx context.Context) (platform.Notifier, error) {
	return h, nil
}

func (h *Config) NotifyDel(en ...*entry.LogEntry) error {
	if h.ens == nil {
		h.ens = make(map[string]*entry.LogEntry)
	}
	for _, v := range en {
		delete(h.ens, v.Client)
	}
	return nil
}

func (h *Config) NotifyAdd(en *entry.LogEntry) error {
	if h.ens == nil {
		h.ens = make(map[string]*entry.LogEntry)
	}
	h.ens[en.Client] = en
	return nil
}

func (h *Config) GetSource(fileHandler platform.Configer, ctx context.Context, tailMode bool) (source.Reader, error) {
	return nil, errors.New("no stumb source")
}

func (h *Config) ListExistedEntrys() (map[string]*entry.LogEntry, error) {
	return nil, errors.New("not supported function")
}

func init() {
	platform.Register("echo", &Config{})
}
